#pragma once


#include <list>
#include <map>
using namespace std;


struct Edge
{
	static const Edge Null;

	int i;
	int j;
	double weight;

	Edge(int i, int j, double weight)
		: i(i), j(j), weight(weight)
	{ }

	bool IsNull() const { return i == -1 && j == -1 && weight == 0; }
};


class IncidenceGraph
{
public:
	IncidenceGraph();
	virtual ~IncidenceGraph();

	void AddVertex(int i);
	void RemoveVertex(int i);
	bool ContainsVertex(int i) const;
	list<int> GetVertices() const;
	int VertexCount() const;

	void AddDirectedEdge(int i, int j, double weight, bool addVertices=true);
	void AddUndirectedEdge(int i, int j, double weight, bool addVertices=true);
	void RemoveEdge(int i, int j);
	void SetEdge(int i, int j, double weight);
	Edge GetEdge(int i, int j) const;
	list<Edge> GetEdges(int i) const;
	bool ContainsEdge(int i, int j) const;
	int EdgeCount() const;
	int EdgeCount(int i) const;

	inline bool IsDirected() const { return isDirected; }

private:
	bool isDirected;
	multimap<int, Edge> incidences;
};

